package com.neuedu.thread.lock;

public class Lock2 implements Runnable {
    @Override
    public void run() {
        try {
            System.out.println("Lock2 running");
            while (true) {
                synchronized (TestLock.objB) {
                    System.out.println("Lock2 lock strB");
                    Thread.sleep(5000);// 获取strA后先等一会儿，让Lock2有足够的时间锁住strB
                    synchronized (TestLock.objA) {
                        System.out.println("Lock2 lock strA");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}